import request from '@/utils/request'
const isMock = true
    /**
     * 创建临时数据
     */
const setpromise = data => {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(data)
        }, 500);
    })
}
export function login(username, password) {
    if (!isMock)
        return setpromise({
            "code": 0,
            "desc": "成功",
            "data": {
                "token": "893594118bbe3982b195232c48482505",
                "user": {
                    "id": "64",
                    "username": "hanjinjin",
                    "email": "mazepeng@quicklyun.com",
                    "mobile": "15801357390",
                    "idcard": "",
                    "nickname": "马泽朋",
                    "is_admin": "1",
                    "status": "1",
                    "order_status": "1",
                    "level": "",
                    "product": "",
                    "desc": "",
                    "extends": "",
                    "create_time": "2018-09-07 21:14:15"
                },
                "roles": [{
                    "id": "1",
                    "name": "management",
                    "router": "/management",
                    "text": "权限管理",
                    "status": "1",
                    "path": "",
                    "children": [{
                        "id": "2",
                        "name": "user",
                        "router": "/management/user",
                        "status": "1",
                        "path": "/user/index",
                        "text": "用户管理"
                    }, ]
                }]
            }
        });
    else
        return request({
            url: '/api/login/',
            method: 'post',
            data: {
                username,
                password
            }
        })
}

export function getUserInfo(token) {
    if (isMock)
        return setpromise({
            "code": 0,
            "desc": "ok",
            "data": {
                "name": "hanjinjin",
                "role": "管理员",
                "tel": '13120004259',
                "isAdmin": "1",
                "roles": [{
                    "id": "1",
                    "name": "management",
                    "router": "/management",
                    "text": "权限管理",
                    "status": "1",
                    "path": "",
                    "children": [{
                        "id": "2",
                        "name": "user",
                        "router": "/management/user",
                        "status": "1",
                        "path": "/user/index",
                        "text": "用户管理"
                    }, ]
                }]
            }
        });
    else
        return request({
            url: '/admin/user/info',
            method: 'get'
        })
}
export function getVerifiCode(data) {
    return request({
        url: '/manager/getVerifiCode',
        method: 'get',
        params: data
    })
}

export function logout() {
    if (!isMock)
        return setpromise({ "code": 0, "desc": "LogOut success", "data": {} });
    else
        return request({
            url: '/api/logout/',
            method: 'post'
        })
}